#include<bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

using namespace std;

const int N = 2e5 + 10;

string s1, s2;

int cx1[N], cx2[N];

int js(string s) {
	int ret = 0;
	for(int i = 0; i < s.size(); i ++ ) {
		if(s[i] == 'r')
		for(int j = i + 1; j < s.size(); j ++ ) {
			if(s[j] == 'e')
			for(int k = j + 1; k < s.size(); k ++ ) {
				if(s[k] == 'd')
				ret ++ ;
			}
		}
	}
	return ret;
}
int main() {
	IOS;
	
	int n, t;
	cin >> n >> t;
	
	cin >> s1 >> s2;
	while(t -- ) {
		int x;
		cin >> x;
		x -- ;
		swap(s1[x], s2[x]);
	//	cout << s1 << " " << s2;
		cout << js(s1) - js(s2) << endl;
	}
	return 0;
}

